import { toastApp } from './toast';
type ExtraData =
	| {
			transaction_id: string;
	  }
	| {
			merchant_trade_no: string;
			merchant_id: string;
	  }
	| {
			merchant_id: string;
			merchant_trade_no: string;
			transaction_id: string;
	  };
	  
	  
export const wxOpenBusinessView = (extraData: ExtraData):Promise<Parameters<NonNullable<Parameters<typeof wx.openBusinessView>[0]['success']>>[0]> =>
	new Promise((resolve, reject) => {
		// #ifdef MP-WEIXIN
		if (wx.openBusinessView) {
			wx.openBusinessView({
				businessType: 'weappOrderConfirm',
				extraData,
				success(res) {
					resolve(res);
					res.errormsg && toastApp(res.errormsg);
				},
				fail() {
					reject({
						code:500
					});
				}
			});
		} else {
			uni.showModal({
				title: '提示',
				content: '微信版本过低，请升级到最新的微信版本'
			});
			reject({
				code:402
			});
		}
		// #endif
		// #ifndef MP-WEIXIN
		reject({
			code:401
		});
		
		// #endif
	});
